import {toast} from "../../utils/tool";

const app = getApp()
Page({
    data: {
        money: 0,
        payOption: [],
        event: '',
    },
    initPayOption() {
        app.ajax({
            url: '/api/recharge/lists',
            success: resp => {
                const {code, data, msg} = resp
                if (code !== 1) {
                    return toast({title: msg})
                }
                if (data && data.length) {
                    console.log(data, 'options')
                    this.setData({
                        payOption: [...data]
                    })
                }
            }
        })
    },
    onLoad: function (options) {
        let _event = ''
        if (options.hasOwnProperty('event')) {
            const {event} = options
            _event = event
        }
        this.initPayOption()
        const {globalData: {userInfo}} = app
        if (!!userInfo) {
            const {money} = userInfo
            this.setData({
                money,
                event: _event
            })
        }
    }
});
